#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>



//void sort(int* num,int n)
//{
//	assert(num);
//	int left = 0;
//	int right = n - 1;
//	while (left < right)
//	{
//		if (num[left] > num[right])
//			Swap(num + left, num + right);
//		right--;
//	}
//	
//}
//
//int* sortedSquares(int* nums, int numsSize, int* returnSize)
//{
//	assert(nums);
//	int* result = (int*)calloc(numsSize, sizeof(int));
//	*returnSize = numsSize;
//	assert(result);
//	int left = 0;
//	int right = 0;
//	while (left <= numsSize - 1 && nums[left] < 0)
//		left++;
//	right = left--;
//	int loc = 0;
//	while (left >= 0 && right <= numsSize - 1)
//	{
//		result[loc++] = nums[left] * nums[left] < nums[right] * nums[right] ?
//			nums[left] * nums[left--] : nums[right] * nums[right++];
//	}
//	while (left >= 0)
//		result[loc++] = nums[left] * nums[left--];
//	while (right <= numsSize - 1)
//		result[loc++] = nums[right] * nums[right++];
//	return result;
//}
void Swap(int* x1, int* x2)
{
	assert(x1 && x2);
	int tmp = *x1;
	*x1 = *x2;
	*x2 = tmp;
}

void Reverse(int* begin, int left,int right)
{
	assert(begin);
	while (left < right)
	{
		Swap(begin + left, begin + right);
		left++;
		right--;
	}
}

void rotate(int* nums, int numsSize, int k)
{
	assert(nums);
	k %= numsSize;
	Reverse(nums, 0, numsSize - k - 1);
	Reverse(nums, numsSize - k, numsSize - 1);
	Reverse(nums, 0, numsSize - 1);
}
int main()
{

	int a[] = { 1,2,3,4,5,6,7 };
	int i = 0;
	rotate(a, 7, 3);
	//int* num = sortedSquares(a, sizeof(a) / sizeof(a[0]), &i);
	for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
		printf("%d ", a[i]);



	return 0;
}

